const express = require('express');
const app = express();
const PORT = 3000;



// 解析 JSON 请求体
app.use(express.json());

// 引入并挂载路由模块
const custTree = require('./routes/custTree');

app.use('/custTree', custTree);       // http://localhost:3000/custTree/hello 

// POST /api/login
app.post('/api/login', (req, res) => {
  const { username, password } = req.body;
  if (username === 'admin' && password === '123456') {
    res.json({ code: 0, message: '登录成功' });
  } else {
    res.json({ code: 1, message: '用户名或密码错误' });
  }
});

// POST /api/register
app.post('/api/register', (req, res) => {
  const { username, email } = req.body;
  res.json({ code: 0, message: `用户 ${username} 注册成功，邮箱 ${email}` });
});

// POST /api/echo
app.post('/api/echo', (req, res) => {
  res.json({
    code: 0,
    message: '你发送的数据如下',
    data: req.body,
  });
});

// 启动服务
app.listen(PORT, () => {
  console.log(`🚀 Server is running on http://localhost:${PORT}`);
});

